home *** CD-ROM | disk | FTP | other *** search
/ Magnum One / Magnum One (Mid-American Digital) (Disc Manufacturing).iso / d12 / c_lib.arc / PCDOSCMD.C < prev    next >
Text File  |  1990-08-09  |  3KB  |  88 lines

  1. /**
  2. *
  3. *  Name         pcdoscmd -- Execute a DOS command
  4. *
  5. *  Synopsis     ercode = pcdoscmd(pcmd);
  6. *               int  ercode       Returned error code
  7. *               char *pcmd        Command to execute
  8. *
  9. *  Description  PCDOSCMD invokes a secondary copy of the command
  10. *               processor to load and execute a DOS command.  This is
  11. *               accomplished by making a call to PCEXEC (to load the
  12. *               command processor) passing the command as the command
  13. *               line.  The function PCENVCHK returns the COMSPEC=
  14. *               parameters, which gives the path name for the command
  15. *               processor.  If the command processor cannot be found,
  16. *               an error is returned.
  17. *
  18. *  Returns      ercode            Returned status code.  Values
  19. *                                 between -18 and 18 are codes returned
  20. *                                 from PCEXEC.  Other value is:
  21. *                                 19 - COMPSPEC= could not be found in
  22. *                                      the environment.  This is an error
  23. *                                      returned from pcenvchk.
  24. *                                 20 - Command processor could not be found
  25. *
  26. *  Version      1.1  (C)Copyright Blaise Computing Inc.  1983, 1984
  27. *
  28. **/
  29. #include <compiler.h>
  30.  
  31. #if LDATA
  32. #define NULL    0L
  33. #else
  34. #define NULL    0
  35. #endif
  36.  
  37. struct dreg
  38. {
  39.   unsigned ax,bx,cx,dx,si,di,ds,es;
  40. };
  41. #define DOSREG  struct dreg
  42.  
  43. int pcdoscmd(pcmd)
  44. char *pcmd;
  45. {
  46.  
  47.     char   *pcenvchk(),*pcomspec,*pdoscmd,*calloc();
  48.     int    dos(),ercode;
  49.     DOSREG dos_reg;
  50. #if CI201A & LDATA
  51.     unsigned long ptrtoabs();
  52. #endif
  53.  
  54.     pcomspec = pcenvchk("COMSPEC=",64);
  55.     if (pcomspec == NULL)
  56.        return(19);                     /* Problem with the environment */
  57.  
  58.     /* Now make sure the file is there by calling function 4E (SFIRST) */
  59.  
  60.     utinit(&dos_reg);
  61.     dos_reg.ax = 0x4e00;
  62. #if LDATA
  63. #if CI201A
  64.     dos_reg.ds = (unsigned)((ptrtoabs(pcomspec) & 0xffff0L) >> 4L);
  65.     dos_reg.dx = (unsigned)(ptrtoabs(pcomspec) & 0xfL);
  66. #else
  67.     dos_reg.ds = (unsigned)(((long)(pcomspec) & 0xffff0L) >> 4L);
  68.     dos_reg.dx = (unsigned)((long)(pcomspec) & 0xfL);
  69. #endif
  70. #else
  71.     dos_reg.dx = (unsigned)pcomspec;
  72. #endif
  73.     if (dos(&dos_reg))
  74.        return(20);                     /* Cannot find COMMAND.COM      */
  75.  
  76.     pdoscmd = calloc(128,1);
  77.     strcat(pdoscmd,"/C");
  78.     strcat(pdoscmd,pcmd);
  79.     strcat(pdoscmd,"\015");
  80.     ercode = pcexec(pcomspec,pdoscmd);
  81.  
  82.     free(pcomspec);
  83.     free(pdoscmd);
  84.  
  85.     return(ercode);
  86.  
  87. }
  88.